from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from django.contrib import admin
from shop.models import (Category, Product, Rating, UserProfile, Order,
                         OrderProduct, Address)


class UserProfileInline(admin.StackedInline):
    model = UserProfile


class AddressAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'street_address', 'postal_code', 'city',
                    'country')
    list_editable = ('name', 'street_address', 'postal_code', 'city', 'country')


class CustomUserAdmin(UserAdmin):
    list_display = ('username', 'email', 'first_name', 'last_name', 'is_staff')
    inlines = [UserProfileInline]


class CategoryAdmin(admin.ModelAdmin):
    list_display = ('id', 'name', 'position')
    list_editable = ('name', 'position',)


class OrderProductInline(admin.TabularInline):
    model = OrderProduct


class OrderAdmin(admin.ModelAdmin):
    inlines = [OrderProductInline]
    list_display = ('id', 'user', 'created', 'total_price', 'status', 'shipped',
                    'shipping_address')
    list_editable = ('status',)
    list_filter = ('status', )


class ProductAdmin(admin.ModelAdmin):
    list_display = ('name', 'price', 'stock', 'category')
    list_filter = ('category', )
    list_editable = ('price', 'stock', 'category')
    ordering = ('name',)


class RatingAdmin(admin.ModelAdmin):
    list_display = ('user', 'product', 'stars')


admin.site.unregister(User)
admin.site.register(Address, AddressAdmin)
admin.site.register(User, CustomUserAdmin)
admin.site.register(Category, CategoryAdmin)
admin.site.register(Product, ProductAdmin)
admin.site.register(Rating, RatingAdmin)
admin.site.register(Order, OrderAdmin)

